<?php defined('_JEXEC') or die('Restricted access'); ?>

<?php JHTML::_('behavior.tooltip'); ?>

<?php
	$edit = JRequest::getVar('edit',true);
	$text = intval($edit) ? JText::_( 'Edit' ) : JText::_( 'New' );

	$delete = $this->reg->del;

	$text = $delete ? 'Usunięty' : $text;
	JToolBarHelper::title( 'Region' . ': <small><small>[ '. $text .' ]</small></small>' , 'region.png' );
	JToolBarHelper::pdf();

	global $form_edit;
	// Zablokowanie edycji "archiwalnych" dla administratora
	$form_edit = ( $form_edit == true && $delete == 0 );
	
	if ( $form_edit ) {
		JToolBarHelper::save();
		JToolBarHelper::cancel();
	} else  { 
		JToolBarHelper::back2();
	}

	//JToolBarHelper::help( 'screen.regiony.edit' );
?>

<script language="javascript" type="text/javascript">
	function submitbutton(pressbutton) 
	{
		var form = document.adminForm;
		if (pressbutton == 'cancel') {
			submitform( pressbutton );
			return;
		}

		// do field validation
		if (trim(form.nrr.value) == "" || form.nrr.value == 0)  {
			alert( "Podaj numer regionu!" );
		} else if  (trim(form.n_reg.value) == "") {
			alert( "Podaj nazwę regionu!" );
		} else {
			submitform( pressbutton );
		}
	}
</script>

<form action="index.php" method="post" name="adminForm" autocomplete="off">
	<div class="col">
		<fieldset class="adminform">
		<legend><?php echo 'Szczegóły regionu'; ?></legend>
			<table class="admintable" cellspacing="1">
				<tr>
					<td width="150" class="key">
						<label for="nrr">
							Nr regionu
						</label>
					</td>
					<td>
					<?php if ( $form_edit ) { ?>
					       	       <input type="text" name="nrr" id="nrr" class="inputbox"                     style="width:400px;" value="<?php echo htmlspecialchars($this->reg->get('nrr')); ?>" />
					<?php } else {  ?>
					       	       <input type="text" name="nrr" id="nrr" class="inputbox" readonly="readonly" style="width:400px;" value="<?php echo htmlspecialchars($this->reg->get('nrr')); ?>" />
					 <?php } ?>
					</td>
				</tr>
				<tr>
					<td width="150" class="key">
						<label for="n_reg">
							Nazwa regionu
						</label>
					</td>
					<td>
					<?php if ( $form_edit ) { ?>
						<input type="text" name="n_reg" id="n_reg" class="inputbox"                     style="width:400px;" value="<?php echo htmlspecialchars($this->reg->get('n_reg')); ?>" />
					<?php } else {  ?>
						<input type="text" name="n_reg" id="n_reg" class="inputbox" readonly="readonly" style="width:400px;" value="<?php echo htmlspecialchars($this->reg->get('n_reg')); ?>" />
					 <?php } ?>
					</td>
				</tr>
				<tr>
					<td width="150" class="key">
						<label for="users">
							Kierownik regionu
						</label>
					</td>
					<td>
					<?php if ( $form_edit ) { 
						    echo $this->lists['kier'];
					       } else {  ?>
						     <input type="text" class="inputbox" readonly="readonly"  style="width:400px;" value="<?php echo htmlspecialchars($this->reg->get('name')); ?>" />       	       
					 <?php } ?>
					</td>
				</tr>
			</table>
		</fieldset>
<?php if ($this->reg->get('id') && $delete) { ?>
	<fieldset class="adminform">
	<legend><?php echo 'Region został usunięty'; ?></legend>
		<table class="admintable" cellspacing="1">
			<tr>
				<td class="key">
					<?php echo 'w dniu'; ?>
				</td>
				<td>
					<?php echo $this->reg->registerDate; ?>
				</td>
			</tr>			
			<tr>
				<td class="key">
					<?php echo 'przez'; ?>
				</td>
				<td>
					<?php echo $this->reg->whoRegister; ?>
				</td>
			</tr>	
		</table>
	</fieldset>
<?php } ?>
	</div>
	<div class="clr"></div>

	<input type="hidden" name="gid" value="<?php echo $this->reg->get('gid'); ?>" />
	<input type="hidden" name="del" value="<?php echo $this->reg->get('del'); ?>" />
	<input type="hidden" name="option" value="com_regiony" />
	<input type="hidden" name="task" value="" />
	<?php echo JHTML::_( 'form.token' ); ?>
</form>
